<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system 
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : exchange.class.php   FILE_PATH : E:\www\\trunk\classes\application\exchange.class.php
 * ....汇率管理类
 *
 * @copyright workflow_system 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Fri May 23 10:48:05 CST 2008
 */

class ExchangeClass extends FrameWork {
	//默认的汇率标准换算货币,人民币
	var $default_exchange = "CNY";

	/**
	 * 将支付方式支持的货币种类添加到汇率表中
	 * @author workflow Develop Team     
	 * @param  $cur_array 货币种类数组
	 * @return bool
	 */
	function setupExchange($cur_array){
		//判断默认的汇率标准货币信息是否存在，没有则添加，目前是RMB
		$exchange = $this->default_exchange;
		$result = $this->checkExistsExchange($exchange);
		if (false == $result){//当不存在的时候，添加
			$param_array = array();
			$param_array['exchange_name'] = $exchange;
			$param_array['state'] = 1;
			$this->addExchange($param_array);
			unset($param_array);
		}
		//添加除了$this->default_exchange以外的其他货币种类
		if (is_array($cur_array)){
			foreach ($cur_array as $k){
				if ($k != $exchange){
					if ($this->checkExistsExchange($k) == false){
						$param_array = array();
						$param_array['exchange_name'] = $k;
						$param_array['state'] = 0;
						$this->addExchange($param_array);
						unset($param_array);
					}
				}
			}
		}
		return true; 
	}
	
	/**
	 * 判断默认的汇率标准货币信息是否存在
	 * @author workflow Develop Team     
	 * @param  
	 * @return bool
	 */
	function checkExistsExchange($exchange){
		$condition['exchange_name'] = $exchange;
		$exchange_array = $this->listExchange($condition,$page);
		if (empty($exchange_array)){
			return false;
		}
		return true;
	}
	
	/**
	 * 汇率信息列表
	 * @author workflow Develop Team     
	 * @param  $condition 检索条件 $obj_page 分页对象
	 * @return array
	 */
	function listExchange($condition,&$obj_page){
		$condition_str = $this->_conditionSearch($condition);
		$exchange_array = $GLOBALS['db']->GetList($condition_str, $obj_page, "exchange");
		return $exchange_array;
	}
	
	
	/**
	 * 构造检索条件
	 * @author workflow Develop Team     
	 * @param  $condition检索条件
	 * @return string
	 */
	function _conditionSearch($condition){
		$condition_str = "";
		//货币种类
		if ($condition['exchange_name'] != ''){
			$condition_str .= " and exchange_name='" . $condition['exchange_name'] . "'";
		}
		//不包括的货币种类
		if ($condition['no_name'] != ''){
			$condition_str .= " and exchange_name != '" . $condition['no_name'] . "'";
		}
		//状态
		
		if ($condition['state'] != ''){
			$condition_str .= " and state='" . $condition['state'] . "'";
		}
		return $condition_str;
	}
	
	
	/**
	 * 添加汇率信息
	 * @author workflow Develop Team     
	 * @param  $param_array 
	 * @return bool
	 */
	function addExchange($param_array){
		if (is_array($param_array)){
			$value_array = array();
			foreach ($param_array as $k => $v){
				if ($v !== ''){
					$value_array[$k] = $v;
				}
			}
			$result = $GLOBALS['db']->InsertRow($value_array,"exchange","exchange_id");
			return $result;
		}else {
			return false;
		}
	}
	
	/**
	 * 更新汇率信息
	 * @author workflow Develop Team     
	 * @param  $param_array 参数
	 * @return int/bool/object/array
	 */
	function updateExchange($param_array){
		if (is_array($param_array)){
			$value_array = array();
			foreach ($param_array as $k => $v){
				if ($v !== ''){
					$value_array[$k] = $v;
				}
			}
			$result = $GLOBALS['db']->UpdateRow($value_array['exchange_id'],$value_array, 'exchange', 'exchange_id');
			return $result;
		}else {
			return false;
		}
	}
	
	/**
	 * 取货币单位对应的一维数组 货币符号----名称
	 * @author workflow Develop Team     
	 * @param  
	 * @return array
	 */
	function getExchangeArray(){
		$exchange_array = $this->listExchange($condition,$page);
		if (is_array($exchange_array)){
			foreach ($exchange_array as $v){
				$array[$v['exchange_name']] = $v['exchange_remark'];
			}
		}
		return $array;
	}
}

?>